package cn.achao.csr.api;

import cn.achao.csr.api.factory.SysUserFallbackFactory;
import cn.achao.csr.api.model.dto.AuthDTO;
import cn.achao.csr.api.model.dto.RegisterDTO;
import cn.achao.csr.api.model.entity.LoginUser;
import cn.achao.csr.api.model.entity.SysUser;
import cn.achao.csr.base.constant.SecurityConstants;
import cn.achao.csr.base.constant.enums.ThirdAuthEnum;
import cn.achao.csr.base.resp.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: achao
 **/
@FeignClient(contextId = "csrSysUserContextId", path = "/user", value = "csr-system", fallbackFactory = SysUserFallbackFactory.class)
public interface SysUserApi {

    /**
     * 注册用户
     * @param req
     * @return
     */
    @PostMapping("/register")
    R<LoginUser> register(@RequestBody @Validated RegisterDTO req);

    /**
     * 根据账号查询用户信息
     * @param userAccount
     * @param source
     * @return
     */
    @GetMapping("/info/{userAccount}")
    R<LoginUser> info(@PathVariable("userAccount") String userAccount,
                      @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 根据支付宝openId查询用户信息
     * @param openId
     * @param source
     * @return
     */
    @GetMapping("/infoByZfbOpenId/{openId}")
    R<LoginUser> infoByZfbOpenId(@PathVariable("openId") String openId,
                                 @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 支付宝授权
     * @param req
     * @param source
     * @return
     */
    @PostMapping("/updateOpenId")
    R<LoginUser> updateZfbOpenId(@RequestBody @Validated AuthDTO req,
                                 @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 是否已经授权过
     * @param openId
     * @param thirdAuthEnum
     * @param source
     * @return
     */
    @GetMapping("/isExistOpenId")
    R<Boolean> isExistOpenId(@RequestParam("openId") String openId,
                             @RequestParam("thirdAuthEnum") ThirdAuthEnum thirdAuthEnum,
                             @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 查询用户列表
     * @param userIds
     * @param source
     * @return
     */
    @GetMapping("/getUserListByIds")
    R<Map<Long, SysUser>> getUserListByIds(@RequestParam("openId") List<Long> userIds,
                                              @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

}
